package com.zhang.crm.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;

public class JSONUtil {
    @Resource
    private static final ObjectMapper objectMapper = new ObjectMapper();
    public static String toJSON(Object o){
        try {
            String s = objectMapper.writeValueAsString(o);
            return s;
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    public static <T> T toObj(String json,Class<T> clazz){
        try {
            T t = objectMapper.readValue(json, clazz);
            return t;
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }

    }
}
